/*=============== Table 1: Sensitivity of Dube Estiamtes to ====================*/


local  dem i.race##i.post2002 i.marst i.famsize i.nchild i.educ i.hispan##i.post2002 i.sex i.nchild##i.pre1988  i.race#i.pre1988
* local  dem i.dem_race##i.post2002  i.dem_race#i.pre1988 i.dem_married i.dem_famsize ///
* i.dem_nchild i.dem_nchild##i.pre1988 i.dem_educ i.dem_female i.dem_hisp##i.post2002

local rhs age* stateeitcrate
local rhs1 `rhs' 
local rhs2 `rhs' unemprate statepcgdp
local rhs3 `rhs' unemprate 
local rhs4 `rhs' statepcgdp
local rhs5 `rhs' hpi
local rhs6 `rhs' ur_high_edu statepcgdp
local rhs7 `rhs' ur_high_edu
local rhs8 `rhs' ur_high_edu wage_high_edu
local rhs9 `rhs' hpi ur_high_edu wage_high_edu
local rhs10 `rhs' unemprate statepcgdp hpi ur_high_edu wage_high_edu
local rhs11 `rhs' hpi  statepcgdp 
local rhs12 `rhs' hpi wage_high_edu
local rhs13 age* hpi ur_high_edu wage_high_edu  eitc tanf4 snap4 ACA
local rhs14 age* hpi ur_high_edu wage_high_edu  eitc tanf4 snap4 ACA

local  a1 year i.state_fips `dem'

local primary

local j .5
* outreg, clear
* local thresholdlist 0.50(0.25)1.75
* local thresholdlist 0.50(0.25).75
* local thresholdlist 2
* local thresholdlist .5  1 1.5 2 3 4
* local thresholdlist .5 1 1.5
local thresholdlist 1 
* local thresholdlist 1
* replace EF1 = 0
local d 1
local j 1
local spec 3

/*========== RUN REGRESSIONS ==========*/
  use "${data1}march_regready_1984.dta", clear
  
  cap drop strecdums2
  cap drop recdums2
  recode year 2008=1 2009=2 2010=3 nonmissing=0, g(recdums2)
  egen strecdums2 = group(recdums2 state_fips)

  cap drop under

  replace eitc = eitc*eitc_ref
  gen under = contpov < `j'
  local q = `j' * 100
  
  di "Poverty threshold `q'"
  sum under if demgroup`d'==1
  

 forvalues spec = 1/12 {
  reghdfe under lnMW `rhs`spec''  [pw=wtsupp] if demgroup`d'==1 , a(`a1') cluster(state_fips)
  est save "${est}ster/other/MW1_`q'_dem`d'_s`spec'_macro_robust", replace

  reghdfe under lnMWF1 lnMW lnMWL1 lnMWL2 lnMWL3 `rhs`spec'' [pw=wtsupp] if demgroup`d'==1 , a(`a1') cluster(state_fips)
  est save "${est}ster/other/MW2_`q'_dem`d'_s`spec'_macro_robust", replace
}



cap drop under
gen under = contpov2 < `j'
local q = `j' * 100

forvalues spec = 13/14 {
reghdfe under lnMW `rhs`spec''  [pw=wtsupp] if demgroup`d'==1 , a(`a1') cluster(state_fips)
est save "${est}ster/other/MW1_`q'_dem`d'_s`spec'_macro_robust", replace

reghdfe under lnMW lnMWL1 lnMWL2 lnMWL3 `rhs`spec'' [pw=wtsupp] if demgroup`d'==1 , a(`a1') cluster(state_fips)
est save "${est}ster/other/MW2_`q'_dem`d'_s`spec'_macro_robust", replace
}


/*========== CREATE TABLES ============*/
local j = 1
local q = `j'*100
local d = 1

use "${data1}march_regready_1984.dta", clear
gen under = contpov < `j'

cap program drop mydisp
program mydisp, eclass
         matrix betass=e(b)
         matrix colnames betass = "E"
         mat list betass
         ereturn repost b = betass, rename
 end


local append outreg, merge(r) starloc(1) var stats(b se) blankrow  merge starlevels(10 5 1) bdec(4) noau  keep(lnMW ) nolegend
local append1 outreg, merge(r) starloc(1) var stats(b se) blankrow  merge starlevels(10 5 1) bdec(4) noau   nolegend

sum under [aw=wtsupp] if demgroup1==1
local DVmean=   `r(mean)'
di `DVmean'


outreg, clear
/*Short Run*/
estimates use "${est}ster/other/MW1_`q'_dem`d'_s2_macro_robust"
lincom lnMW 
local beta = `r(estimate)'
di `beta'
local elas:  di %5.3f `beta'/`DVmean'
di `elas'
lincomest lnMW 
mydisp
outreg, store(r)  starloc(1) replace var stats(b se )  blankrow starlevels(10 5 1) bdec(4) noau nolegend ///
addrow("Elast", "[`elas']"\"","`obs'") ct("","(1)"   )


foreach spec of numlist 3 4 6 7 8 5 11 12 9 13 14 {
  estimates use "${est}ster/other/MW1_`q'_dem`d'_s`spec'_macro_robust"
  lincom lnMW
  local beta = `r(estimate)'
  di `beta'
  local elas:  di %5.3f `beta'/`DVmean'
  di `elas'
  lincomest lnMW
  mydisp
  `append1' addrow("Elast", "[`elas']"\"","`obs'") ct("","(`spec')"   )
}
outreg, replay append(r)

/*Long Run*/
estimates use "${est}ster/other/MW2_`q'_dem`d'_s2_macro_robust"
local obs : display %11.0gc `e(N)'
else local obs
lincom lnMW +lnMWL1 +lnMWL2 +lnMWL3
local beta = `r(estimate)'
di `beta'
local elas:  di %5.3f `beta'/`DVmean'
di `elas'
lincomest lnMW +lnMWL1 +lnMWL2 +lnMWL3 
mydisp
outreg, store(r)  starloc(1) replace var stats(b se )  blankrow starlevels(10 5 1) bdec(4) noau nolegend ///
addrow("Elast", "[`elas']"\"","`obs'") ct("","(1)"   )



foreach spec of numlist 3 4 6 7 8 5 11 12 9 13 14 {
  estimates use "${est}ster/other/MW2_`q'_dem`d'_s`spec'_macro_robust"
  local obs : display %11.0gc `e(N)'
  else local obs
  lincom lnMW +lnMWL1 +lnMWL2 +lnMWL3
  local beta = `r(estimate)'
  di `beta'
  local elas:  di %5.3f `beta'/`DVmean'
  di `elas'
  lincomest lnMW +lnMWL1 +lnMWL2 +lnMWL3
  mydisp
  `append1' addrow("Elast", "[`elas']"\"","`obs'") ct("","(`d')"   )

}

outreg, replay append(r)


outreg using "${est}other_reg/table_macro_cont", statfont( fs12 ) basefont(fs12) replay replace landscape


